<template>
	<view>
		<ljy-header></ljy-header>

		<view class="index-category">
			<scroll-view class="left-menu" scroll-x="ture">
				<view class="category1-menu" :class="index==currentIndex ? 'active' : ''"
					v-for="(item,index) in leftlist" :key="index" @tap="changeIndex(index)">
					{{item}}
				</view>
			</scroll-view>

			<scroll-view class="right-data" scroll-y="true">
				<view class="category2-group" v-for="(item,index) in rightlist" :key="index">
					<view class="category2-title">
						<text class="iconfont icon-shangpin"></text>
						{{item.cat_name}}
					</view>
					<view class="category3-list">
						<navigator class="image-box" v-for="(item2,index2) in item.children" :key="index2"
							:url="'../../subpkg1/goods-list/goods-list?cid='+item2.cat_id">
							<image :src="item2.cat_icon" mode="widthFix"></image>
							<text>{{item2.cat_name}}</text>
						</navigator>
					</view>
				</view>
			</scroll-view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				categorylist: [],
				leftlist: [],
				rightlist: [],
				currentIndex: 0
			}
		},
		methods: {
			async getCategoryList() {
				const res = await this.$Https({
					url: '/categories'
				});
				// console.log(res);
				this.categorylist = res.message;
				this.leftlist = this.categorylist.map(v => v.cat_name);
				this.rightlist = this.categorylist[0].children;
				console.log(this.categorylist);
				console.log(this.leftlist);
				console.log(this.rightlist);
			},
			changeIndex(index) {
				this.currentIndex = index;
				this.rightlist = this.categorylist[index].children;
			}
		},
		onLoad() {
			this.getCategoryList();
		}
	}
</script>

<style lang="scss">
	.index-category {
		flex-direction: column;

		.left-menu {
			white-space: nowrap;
			width: 100%;
			padding: 10rpx 0;
			border-bottom: 1px solid #D9557C;

			.category1-menu {
				display: inline-block;
				margin: 0 10rpx;
				width: 150rpx;
				height: 75rpx;
				line-height: 75rpx;
				text-align: center;
				font-size: 28rpx;
				border-radius: 40px;
				color: white;
				background-color: #ED98B7;

				&.active {
					background-color: #D9557C;
				}
			}
		}

		.right-data {
			background-color: #F8F8F8;

			.category2-group {
				.category2-title {
					width: 200rpx;
					height: 100rpx;
					margin: 0 50rpx;
					display: flex;
					align-items: center;
					justify-content: flex-start;
					color: #D9557C;
					font-size: 40rpx;
					text-align: center;

				}

				.category3-list {
					display: flex;
					flex-wrap: wrap;

					.image-box {
						width: 33.33%;
						display: flex;
						flex-direction: column;
						align-items: center;

						image {
							width: 70%;
						}

						text {
							margin-bottom: 10rpx;
							color: #D9557C;
						}

					}
				}
			}
		}
	}
</style>